Page({
  data: {
    istop: false,
    height: 100,
    value: '',
    list: [],
    pic: [],
    pagenow: 1,
    total: 1,
    text: '加载中...'
  },
  onLoad: function (options) {

  },
  async loadmore() {
    const { pagenow, total, list, pic } = this.data
    if (pagenow >= total) {
      return this.setData({
        text: '没有更多数据了'
      })
    }
    const rek = await getJSON(`/api/goods/list?searchValue=${value}&pageNum=${pagenow + 1}`)
    if (rek.code == '00000') {
      this.setData({
        text: '加载中...',
        pagenow: pagenow + 1,
        list: list.concat(rek.data.list),
        pic: pic.concat(rek.data.list.map((v) => v.pic.split(',')[0]))
      })
    }
  },

  async bintabs(e) {
    const res = await getJSON(`/api/goods/list?searchValue=${e.detail.value}&pageNum=1`)
    if (res.code == '00000') {
      this.setData({
        pagenow: 1,
        text: '没有更多数据了',
        total: res.data.pages,
        value: e.detail.value,
        list: res.data.list,
        pic: res.data.list.map((v) => v.pic.split(',')[0])
      })
    }
  },

  todetail(e) {
    wx.navigateTo({
      url: `../shopdetail/shopdetail?id=${e.currentTarget.dataset.id}`
    })
  }
})
